package com.moli.honjie.s002test.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.moli.honjie.s002test.R;
import com.moli.honjie.s002test.presenter.ControlActivityPresenter;
import com.moli.honjie.s002test.utils.Utils;

/**
 * Created by Administrator on 2018/3/26.
 */

/**
 * 1. LED
 * 2. 马达
 * 3. 温湿度
 * 4. 心率
 * 5. 陀螺仪
 * 6. 关机
 */
public class ControlActivity extends AppCompatActivity {

    private ControlActivityPresenter mActivityPresenter;
    public TextView mTvInfo;
    public TextView mTvCurrentText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_control);

        initView();
        mActivityPresenter = new ControlActivityPresenter(this);
    }

    private void initView() {

        mTvInfo = findViewById(R.id.tv_info);
        mTvCurrentText = findViewById(R.id.tv_current_text);

        findViewById(R.id.click_1).setOnClickListener(mOnClickListener);
        findViewById(R.id.click_2).setOnClickListener(mOnClickListener);
        findViewById(R.id.click_3).setOnClickListener(mOnClickListener);
        findViewById(R.id.click_4).setOnClickListener(mOnClickListener);
        findViewById(R.id.click_5).setOnClickListener(mOnClickListener);
        findViewById(R.id.click_6).setOnClickListener(mOnClickListener);
        findViewById(R.id.click_7).setOnClickListener(mOnClickListener);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mActivityPresenter.onDestroy();
    }

    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Utils.isFastClick()) {
                // 进行点击事件后的逻辑操作

                switch (view.getId()) {
                    case R.id.click_1:
                        mActivityPresenter.clickLed();
                        break;
                    case R.id.click_2:
                        mActivityPresenter.clickMotor();
                        break;
                    case R.id.click_3:
                        mActivityPresenter.clickTemp();
                        break;
                    case R.id.click_4:
                        mActivityPresenter.clickHeart();
                        break;
                    case R.id.click_5:
                        mActivityPresenter.clickGyro();
                        break;
                    case R.id.click_6:
                        mActivityPresenter.clickShutDown();
                        mTvInfo.setText(" 设备已断开连接");
                        break;
                    case R.id.click_7:
                        finish();
                        break;
                    default:
                        break;
                }
            } else {
                Toast.makeText(ControlActivity.this, "哼 就不给你点", Toast.LENGTH_SHORT).show();
            }
        }
    };


}
